#ifndef VIDEO_CHANNEL
#define VIDEO_CHANNEL

#include "base/Bases.h"
#include "commons/SafeQueue.h"

#include <x264.h>
#include <rtmp.h>

class VideoChannel {

    private:

    uint32_t startTime;

    SafeQueue<RTMPPacket *> *&packetQueue;

    int width;
    int height;
    int fps;
    int bitrate;

    x264_t *codec = nullptr;
    x264_picture_t *i420Pic = nullptr;

    int ySize;
    int uvSize;

    pthread_mutex_t mutex;

    protected:

    public:

    VideoChannel(SafeQueue<RTMPPacket *> *&packetQueue);

    ~VideoChannel();

    //设置视频编码信息
    void setVideoEncodeInfo(int width, int height, int fps, int bitrate);

    //设置推流开始时的时间戳
    void setStartTime(uint32_t startTime) {
        this->startTime = startTime;
    }

    //编码NV21帧数据
    void encodeNV21ToRtmp(int8_t *nv21);

    //创建存储VideoDecodeConfig的Packet
    RTMPPacket * createConfigPacket(uint8_t *sps, uint8_t *pps, int sps_len, int pps_len);

    //创建存储H264视频裸数据的Packet
    RTMPPacket * createRawDataPacket(int type, uint8_t *payload, int payloadSize);
};

#endif

